package cn.sumpu.app.guoguojie.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CmsChannel implements Serializable {

	private static final long serialVersionUID = 7023536097584389287L;

	public CmsChannel(){ }
	
	private String identifier;
	private String mark;
	private String name;
	private String parent;
	private Integer deep;
	private Boolean enabled;
	private Date gmtCreated;
	private Date gmtModified;
	private List<CmsChannel> children = new ArrayList<CmsChannel>();
	public static String treeJson = "";
	
	public String getMark() {
        return mark;
    }
    public void setMark(String mark) {
        this.mark = mark;
    }
    public String getIdentifier() {
		return identifier;
	}
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getParent() {
		return parent;
	}
	public void setParent(String parent) {
		this.parent = parent;
	}
	public Integer getDeep() {
		return deep;
	}
	public void setDeep(Integer deep) {
		this.deep = deep;
	}
	public Boolean getEnabled() {
		return enabled;
	}
	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}
	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}
	public Date getGmtModified() {
		return gmtModified;
	}
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public List<CmsChannel> getChildren() {
		return children;
	}
	public void setChildren(List<CmsChannel> children) {
		this.children = children;
	}
	
	//构建树
    public static String buildChannelTree(List<CmsChannel> channelList){
        CmsChannel c = new CmsChannel();
        for(int i=0; i<channelList.size(); i++){
            c = channelList.get(i);
            treeJson += "{\"text\": \""+c.getName()+"\",\"id\":\""+c.getIdentifier()+"\""+",\"mark\":\""+c.getMark()+"\"";
            if(c.getChildren()==null || c.getChildren().size()==0){
                treeJson += ",\"url\":\"/misc/cms/getCmsContent.htm?mark="+c.getMark()+"&cid="+c.getIdentifier()+"\"";
            }
            if(c.getChildren()!=null && c.getChildren().size()>0){
                treeJson += ",\"isexpand\": false ,\"children\": [";
                buildChannelTree(c.getChildren());
                treeJson += "]";
            }
            treeJson += "}";
            if((i+1) < channelList.size()){
                treeJson += ",";
            }
        }
        return treeJson;
    }
    public static String getChannelTree(List<CmsChannel> channelList){
        treeJson = "[";
        String tree = buildChannelTree(channelList);
        tree += "]";
        return tree;
    }

}
